<template>
  <div class="list-content">
    <div class="list-header clearfix">
        <div class="list-header-tit fl">我参与的征集</div>
        <div class="list-close fr" style="font-size: 16px;background:#ffffff;">
            <span @click="backHome">返回首页：</span>
            <img src="../../assets/image/backhome.png" style="width:24px;height:24px;" @click="backHome">
               &nbsp;
            <span  @click="outmything" >意见征集：</span>
            <img src="../../assets/image/jump_to.png" style="width:22px;height:22px;" @click="outmything">
        </div>
    </div>
    <div class="list-table">
      <div class="home-table">
        <table class="app-table">
          <thead>
           <th>标题</th>
           <th>截止日期</th>
           <th>征集状态</th>
          </thead>
          <tbody v-if="list.length">
            <tr v-for="item in list" :key="item.id">
              
              <td class="ellipsis" style="cursor:pointer; width:60%" @click="enterSuggestDet(item)">{{ item.title | filterWords(32) }}</td>
              <td>{{ item.endTime }}</td>
              <td class="clearfix">
              <div v-if="item.isSurvey==2" >进行中</div>
              <div v-else >已结束</div>
              </td>
            </tr>
          </tbody>
          <tbody v-if="!list.length">
            <tr>
              <td>暂无数据</td>
              <td>暂无数据</td>
              <td>暂无数据</td>
            </tr>
          </tbody>
        </table>
      </div>
    </div>
    <div class="page-wrap">
      <el-pagination
        background
        :current-page="pageIndex"
        :page-size="pageSize"
        @current-change="pageChange"
        layout="prev, pager, next,jumper"
        :total="Number(total)"
      >
      </el-pagination>
    </div>
  </div>
</template>

<script>
import { getSuggestList, getUserInfo } from '@/api'
export default {
  data() {
    return {
      list:[],
      pageIndex:1,
      pageSize:10,
      total:0,
      statusList:[
        { name:'待处理',id:1,},
        { name:'处理中',id:2},
        { name:'已处理',id:3},
        { name:'已废止',id:4}
      ],
    };
  },
  computed:{
    getUser(){
      return this.$store.state.user;
    }
  },
  mounted(){
    this.getData();
  },
  methods:{
    backHome(){
      this.$router.push({ name:'home' });
    },
    pageChange(num){
      this.pageIndex = num;
      this.getList();
    },

    outmything(){
      window.open("http://www.sc.gov.cn/10462/10771/10795/yjzj.shtml", "_blank");
    },

    getData(){ // 保证有userid
      if(this.getUser.id){
        this.getList();
      }else{
        let url = '/sys/sysMember/getMember';
        getUserInfo(url).then(res=>{
          if(res.data.code == 200){
            this.$store.commit('setUserinfo',{
              id:res.data.data.id,
              name: res.data.data.realName,
              mobile:res.data.data.mobile,
              userType:res.data.data.userType
            })
            this.getList();
          }
        })
      }
    },
    
    getList() {
                //this.getUser.mobile   

                let url = '/sys/sysMember/getFrontArticleList';
                let params = {
              
                    pageNum: this.pageIndex,
                    pageSize: this.pageSize,
                    phone: this.getUser.mobile 
                }
                getSuggestList(url, params).then(res => {
                    if (res.data.status == 'success') {
                        this.list = res.data.data.rows || [];
                        this.total = res.data.data.total || 0;
                    } else {
                        this.list = [];
                        this.total = 0;
                    }
                })
     },

     enterSuggestDet(item) {
       
                let url = 'http://www.sc.gov.cn/10462/c100410/yjzj01.shtml?id=' + item.id;
                window.open(url, "_blank");
     },
  },
  filters: {
    statusHandler: function (str) {
      if (!str) {
        return "--";
      } else{
        switch(str)
          {
          case 1:
            str = "待处理";
            break;
          case 2:
            str = "处理中";
            break;
          case 3:
            str = "已处理";
            break;
          default:
            str = "已废止";
          }
      }
      return str; 
    }
  }
};
</script>

<style lang="scss" scoped>

</style>
